﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ElectronicJournal
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var currentUser = Membership.GetUser();
            if (currentUser != null)
            {
                if (Roles.IsUserInRole(currentUser.UserName, "Author"))
                {
                    liAuthor.Style.Add("display","block");
                    //HtmlGenericControl li = new HtmlGenericControl("li");
                    //HtmlGenericControl anchor = new HtmlGenericControl("a");
                    //anchor.Attributes.Add("href", "/Account/AuthorAccount/MyAccount.aspx");
                    //anchor.Attributes.Add("ID", "authorsAnchor");
                    //anchor.InnerText = "Публикации";
                    //li.Controls.Add(anchor);
                    //Authors.Controls.Add(li);
                }
                else if (Roles.IsUserInRole(currentUser.UserName, "Reviewer"))
                {
                    liReviewer.Style.Add("display", "block");
                    //HtmlGenericControl li = new HtmlGenericControl("li");
                    //HtmlGenericControl anchor = new HtmlGenericControl("a");
                    //anchor.Attributes.Add("href", "/Account/ReviewerAccount/Reviewer.aspx");
                    //anchor.Attributes.Add("ID", "reviewersAnchor");
                    //anchor.InnerText = "Статьи на рецензирование";
                    //li.Controls.Add(anchor);
                    //Reviewers.Controls.Add(li);
                }
            }
        }

        protected void HeadLoginView_ViewChanged(object sender, EventArgs e)
        {

        }

        protected void ToCabitenLinkClick(object sender, EventArgs e)
        {
            MembershipUser user = Membership.GetUser();
            if (user != null)
                if (Roles.IsUserInRole(user.UserName, "Reviewer"))
                {
                    Response.Redirect("/Account/ReviewerAccount/Default.aspx");
                } 
                else if(Roles.IsUserInRole(user.UserName, "Author"))
                {
                    Response.Redirect("/Account/AuthorAccount/Default.aspx");
                }
                else if(Roles.IsUserInRole(user.UserName, "Administrator"))
                {
                    Response.Redirect("/Account/ReviewerAccount/Default.aspx");
                }
                else if (Roles.IsUserInRole(user.UserName, "Editor"))
                {
                    Response.Redirect("/Account/EditorAccount/Default.aspx");
                }
        }
    }
}
